namespace SmartSoft.ADP
{
    using System;
    using System.Data;
    using System.Data.SqlClient;

    public class CDZDataAccess
    {
        private WSCDZDataAccess.WSCDZDataAccess wDataAcess = new WSCDZDataAccess.WSCDZDataAccess();
        private SmartSoft.DAL.CDZDataAccess oDataAcess = new SmartSoft.DAL.CDZDataAccess();

        public CDZDataAccess()
        {
            wDataAcess.Url = wDataAcess.Url.Replace("localhost", AdapterInstance.ServerIp);
        }

        public bool Delete(object po_KeyCode)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.Delete(po_KeyCode == DBNull.Value ? string.Empty : po_KeyCode);
            }
            else
            {
                return oDataAcess.Delete(po_KeyCode);
            }
        }

        public DataTable GetDataTable(string ps_Subsidiary, object pd_Ngay_Ct, object ps_Loai_DD)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetDataTable(ps_Subsidiary, pd_Ngay_Ct, ps_Loai_DD);
            }
            else
            {
                table= oDataAcess.GetDataTable(ps_Subsidiary, pd_Ngay_Ct, ps_Loai_DD);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public DataTable GetDataTable(string ps_Subsidiary, object pd_Ngay_Ct, object ps_Loai_DD, object ps_Code)
        {
            DataTable table = null;
            if (AdapterInstance.IsRemoteConnected)
            {
                table= wDataAcess.GetDataTable(ps_Subsidiary, pd_Ngay_Ct, ps_Loai_DD, ps_Code);
            }
            else
            {
                table= oDataAcess.GetDataTable(ps_Subsidiary, pd_Ngay_Ct, ps_Loai_DD, ps_Code);
            }
            if (table != null) table.TableName = string.Empty;
            return table;
        }

        public int Save(bool pb_NewChecked, DataRow row)
        {
            if (AdapterInstance.IsRemoteConnected)
            {
                return wDataAcess.Save(pb_NewChecked, SmartSoft.DAL.SSDataAccess.ConvertRowToTable(row));
            }
            else
            {
                return oDataAcess.Save(pb_NewChecked, row);
            }
        }
    }
}

